package com.wx.lock.redis;


import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author wx
 * @Description: 分布式锁测试
 * @date 2018/12/1
 */
public class LockMain {

	private static final int threadNum = 10;
	private static final CountDownLatch latch = new CountDownLatch(threadNum);

	public static void main(String[] agrs) {
		ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 10, 200, TimeUnit.MILLISECONDS,
				new ArrayBlockingQueue<Runnable>(5));
		Service service = new Service();
		for (int i = 0; i < threadNum; i++) {
			final int code = i;
			executor.execute(new Runnable() {
				@Override
				public void run() {
					service.seckill();
					latch.countDown();
				}

			});

		}
		try {
			latch.await();
			System.out.println("所有线程执行完毕");
			executor.shutdown();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
